//index.js
//获取应用实例
var app = getApp();
Page({
  data: {
    remind: '加载中',
    angle: 0,
    userInfo: {},
    time:3
  },
  goToIndex: function () {
    console.log(1);
    wx.navigateTo({
      url: '/pages/home/home',
    });
  },
  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '这里是标题',
      path: '/pages/index/index'
    }
  },
  onLoad: function () {
    var that = this
    app.getUserInfo(function (userInfo) {
      console.log(userInfo)
      that.setData({
        userInfo: userInfo
      })
    })
  },
  onShow: function () {

  },
  onReady: function () {
    var that = this;
    function timeDown() {
      let time = that.data.time;
      if (time == 0) {
        wx.switchTab({
          url: '/pages/home/home'
        });
        return;
      }
      setTimeout(function () {
        let time = --that.data.time;
        that.setData({
          time: time
        });
        timeDown();
      }, 1000);
    }
    console.log(
app.globalData.userInfo)
    setTimeout(function () {
      that.setData({
        remind: ''
      });
      timeDown();
    },1500);
    wx.onAccelerometerChange(function (res) {
      var angle = -(res.x * 30).toFixed(1);
      if (angle > 14) { angle = 14; }
      else if (angle < -14) { angle = -14; }
      if (that.data.angle !== angle) {
        that.setData({
          angle: angle
        });
      }
    });
  }
});